Repository navigation
fix(config): migrate by editing the text, so it stops deleting every comment - #515
Merged
Merged
Conversation
…comment `kit config migrate` re-serialised .kit.toml from the parsed object, so every comment in the file was deleted. Measured on kit's own config, on the v0 -> v1 step whose entire job is to stamp `version = 1`: 8 comment lines became 0, and a one-line change produced a 36-line diff. The parsed data was identical, so the backup-and-re-validate path passed and flagged nothing — and neither did the dry run, which previewed `+ version = 1` and said nothing about the rewrite. What was lost was policy reasoning: why those scanners are declared, why the refs are aqua:-scheme-qualified (bare names are untriageable and the gate blocks them), where the scanner tokens resolve from, and an inline comment documenting the accepted values of `environment`. .kit.toml is where a repo declares its policy, and kit's argument is that policy should be reviewable. An add-only migration is now applied as a TEXT EDIT: the key is inserted above the first table (top-level keys must precede it, or TOML scopes them into that table) and the rest of the file is untouched. patchConfigText returns null for anything more structural — a changed value, a removal, a nested addition — rather than being forced through an edit that cannot express it; the run then refuses while comments exist unless --allow-comment-loss is passed, naming how many lines are at stake. --dry-run now says which path it would take: "Applied as a text edit: comments and formatting are preserved", or the count that would be deleted. A preview that omits the destructive half of a change is worse than no preview. Closes #513 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
✅ Docker image built successfully
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #513.
Measured, on kit's own config
The v0 → v1 step's entire job is to stamp
version = 1:The parsed data was identical apart from
version, so the backup-and-re-validate safety path passed and nothing flagged the loss. What went with it was policy reasoning — why those scanners are declared, why the refs areaqua:-scheme-qualified (bare names are untriageable and the gate blocks them), where the scanner tokens resolve from, and an inline comment documenting the accepted values ofenvironment.The fix
Add-only migrations are applied as a text edit. The key is inserted above the first table — top-level keys must precede it, or TOML scopes them into that table — and everything else is left byte-for-byte:
Anything more structural refuses rather than guesses.
patchConfigTextreturnsnullfor a changed value, a removal, or a nested addition, because a line insert cannot express those. The caller then falls back to serialising — and while comments exist, that is refused:The dry run says which path it would take, since that was the sharper half of the defect: a preview showing a one-line change before a thirty-six-line rewrite is worse than no preview.
Tests
src/config-migrate-text.test.ts— 7:patchConfigTextreturns null for a changed value, a removal, a nested addition, and an empty diff — so a future migration cannot be silently mis-applied by a text editcountCommentLinescounts full-line and inline comments--dry-runstates the path and writes nothing;--checkstill exits 1 on a stale config without touching the fileVerification
npm test: 4446 tests, 0 fail, 0 skipped (macOS, non-root)kit self-audit: 16 rules, 0 fail, 0 warn ·eslint src: 0 errors ·prettier --checkclean--allow-comment-loss), and the flag is documented indocs/COMMANDS.md— flags are not caught by theundocumented commandsrule, so that one is discipline🤖 Generated with Claude Code